﻿#include "OperViewport.h"

#include "GUIFrame/MainWindow.h"
#include "GUIFrame/CentralWidget.h"
#include "GUIWidget/GraphArea.h"
#include "OperatorsInterface/GraphEventOperator.h"

#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Component/FITKWidget/FITKMdiArea.h"

namespace ModelOper
{
    bool OperViewport::execGUI()
    {
        if (_emitter == nullptr) {
            return false;
        }

        GUI::MainWindow* mainWindow = dynamic_cast<GUI::MainWindow*>(FITKAPP->getGlobalData()->getMainWindow());
        if (mainWindow == nullptr) {
            return false;
        }

        GUI::GraphArea* graphArea = mainWindow->getCentralWidget()->getGraphArea();
        if (graphArea == nullptr) {
            return false;
        }

        Comp::FITKMdiArea* mdiArea = graphArea->getMdiArea();
        if (mdiArea == nullptr) {
            return false;
        }

        EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
        if (graphOper == nullptr){
            return false;
        }
        QString emitName = _emitter->objectName();
        if (emitName == "actionWindowCreat") {
            graphArea->createNewPreWindow();
            graphOper->updateAll(true);
        }
        else if (emitName == "actionWindowDelete") {

        }
        else if (emitName == "actionWindowTileHorizontal") {
            mdiArea->setLayoutType(Comp::FITKVportsLayoutType::TileHorizontally);
        }
        else if (emitName == "actionWindowTilingVertical") {
            mdiArea->setLayoutType(Comp::FITKVportsLayoutType::TileVertically);
        }
        else if (emitName == "actionWindowCascade") {
            mdiArea->setLayoutType(Comp::FITKVportsLayoutType::Cascade);
        }
        else if (emitName == "actionWindowManage") {

        }
        return true;
    }

    bool OperViewport::execProfession()
    {
        return true;
    }
}